import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split #继承划分训练集和测试机
from sklearn.neighbors import KNeighborsClassifier  #K近邻
import matplotlib.pyplot as plt
from collections import Counter     #用于统计分类正确的样本数
from sklearn.preprocessing import StandardScaler#导入用于归一化的包
from sklearn.model_selection import cross_val_score#k折
from sklearn.naive_bayes import GaussianNB


AF_input_frame=pd.read_excel('pre_treatment_data.xlsx',sheet_name='AF_input')
nonAF_input_frame=pd.read_excel('pre_treatment_data.xlsx',sheet_name='nonAF_input')
AF_label_frame=pd.read_excel('pre_treatment_data.xlsx',sheet_name='AF_label')
nonAF_label_frame=pd.read_excel('pre_treatment_data.xlsx',sheet_name='nonAF_label')

AF_input=AF_input_frame.to_numpy()
nonAF_input=nonAF_input_frame.to_numpy()
AF_label=AF_label_frame.to_numpy()
nonAF_label=nonAF_label_frame.to_numpy()

AF_label=AF_label.flatten()
nonAF_label=nonAF_label.flatten()

print(AF_input.shape,nonAF_input.shape,AF_label.shape,nonAF_label.shape)

X=np.concatenate([AF_input,nonAF_input])
print(X.shape)
#raw_x=np.reshape(X[:,0],[-1,1])#均值象
#raw_y=np.reshape(X[:,1],[-1,1])#标准差
raw_x=X
print(raw_x.shape)

raw_y=np.concatenate([AF_label[0:],nonAF_label[0:]])
acc_list=[]

from sklearn.preprocessing import StandardScaler
ss=StandardScaler()#
#raw_x=ss.fit_transform(raw_x)#

from sklearn import preprocessing
min_max_normalizer=preprocessing.MinMaxScaler(feature_range=(0,1))
#raw_x=min_max_normalizer.fit_transform(raw_x)#

#k=10
m_min=10
m_max=10
m_interval=1
index=np.array((range(m_min,m_max+1,m_interval)))
from sklearn.model_selection import cross_val_score
#k=10
for k in range(m_min,m_max+1,m_interval):
    model=GaussianNB()
    acc=cross_val_score(model,raw_x,raw_y,cv=k,scoring="accuracy")
    mean_acc=np.array(acc).mean()
    print(mean_acc)
    acc_list.append(mean_acc)